package org.example.myleet.p933;

import java.util.Deque;
import java.util.LinkedList;

public class RecentCounter {

    private Deque<Integer> deque;

    public RecentCounter() {
        deque = new LinkedList<>();
    }

    public int ping(int t) {
        deque.offer(t);
        int threshold = t - 3000;
        Integer tail = deque.peekFirst();
        while (tail < threshold) {
            deque.poll();
            tail = deque.peekFirst();
        }
        return deque.size();
    }
}
